<template>
  <div>
    <div style="width: 1300px;background-color: #eee;height: 500px;margin: 0 auto">
      <el-upload
        class="avatar-uploader"
        action="http://localhost:8081/upload"
        :show-file-list="false"
        :on-success="handleAvatarSuccess"
        :before-upload="beforeAvatarUpload">
        <img v-if="formLabelAlign.adminPic" :src="formLabelAlign.adminPic" class="avatar">
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>

      <el-form label-position="right" label-width="80px" :model="formLabelAlign">
        <el-form-item label="名称">
          <el-input v-model="formLabelAlign.adminName" readonly></el-input>
        </el-form-item>
        <el-form-item label="活动区域">
          <el-input v-model="formLabelAlign.adminPass"></el-input>
        </el-form-item>
      </el-form>
      <el-button @click="update">确认修改</el-button>


    </div>
  </div>
</template>
<script>
import {data} from "autoprefixer";

export default {
  data() {
    return {
      formLabelAlign: {

      }
    };
  },
  methods: {
    handleAvatarSuccess(res, file) {
      console.log(res.data)
      this.formLabelAlign.adminPic = res.data
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    },
    findAdminUser(){
      this.$axios.get('/admin/findadmin').then(res=>{
        this.formLabelAlign = res.data.data
      })
    },
    update(){
      this.$axios.post("/admin/updateadmin",this.formLabelAlign).then(data=>{
        if (data.data.code==200){
          alert("修改成功")
        }else if (data.data.code==666){
          alert("修改成功")
          this.$router.push("/login")
        }else {
          alert("修改失败")
        }
      })
    }
  },
  mounted() {
    this.findAdminUser()
  }
};
</script>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}

</style>
